package bag.dao.impl;

import bag.config.C3P0Utils;
import bag.dao.BookDao;
import bag.domain.Book;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by Administrator on 2017/10/9.
 */
public class BookDaoImpl implements BookDao{

    @Override
    public List<Book> findAll() {
        QueryRunner runner = new QueryRunner(C3P0Utils.getDataSources());
        String sql = "select * from book";
        try {
            List<Book> list = (List<Book>) runner.query(sql,new BeanListHandler(Book.class));
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
